package com.example.consult.service;

import com.example.consult.mapper.QuestionMapper;
import com.example.consult.model.QuestionTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionService {
    @Autowired
    QuestionMapper questionMapper;

    public int setClickTime(String title){
        int time = questionMapper.getClickTime(title);
        time=time+1;
        questionMapper.setClickTime(time,title);
        return time;
    }

    public List<QuestionTable> getQuestionByTitle(String title){
        List<QuestionTable> list = questionMapper.getQuestionByTitle(title);
        for (QuestionTable questionTable : list) {
            int time = questionTable.getClick_time();
            questionMapper.setClickTime(time + 1, title);
        }
        return list;
    }

    public List<QuestionTable> getQuestionByClassify(String classify,String title){
        List<QuestionTable> list = questionMapper.getQuestionByClassify(classify,title);
        for (QuestionTable questionTable : list) {
            int time = questionTable.getClick_time();
            questionMapper.setClickTime(time + 1, title);
        }
        return list;
    }

}
